import {UploadApiResult} from './model/uploadModel';
import {defHttp} from '/@/utils/http/axios';
import {UploadFileParams} from '/#/axios';
import {useGlobSetting} from '/@/hooks/setting';
import {UploadBizType} from '/@/enums/uploadEnum';

const globSetting = useGlobSetting();
const apiUrl = globSetting.apiUrl;

/**
 * 上传父路径
 */
export const uploadUrl = `/infra-service/file/upload`;

/**
 * @description: Upload interface
 */
export function uploadApi(
  params: UploadFileParams, 
  onUploadProgress: (progressEvent: ProgressEvent) => void, 
  isReturnResponse : boolean = false) {
  return defHttp.uploadFile<UploadApiResult>(
    {
      url: uploadUrl,
      onUploadProgress,
    },
    params,
    { isReturnResponse }
  );
}
/**
 * @description: Upload interface
 */
export function uploadImg(params: UploadFileParams, onUploadProgress: (progressEvent: ProgressEvent) => void) {
  console.log("upload image, params: ", params);
  
  return defHttp.uploadFile<UploadApiResult>(
    {
      url: `${uploadUrl}?bizType=${UploadBizType.GENERAL_IMAGE}`,
      onUploadProgress,
    },
    {...params},
    { isReturnResponse: true }
  );
}
